package openapi

import (
	"github.com/getkin/kin-openapi/openapi3"
)

//针对一个定义的请求选项
type OperationSelection struct {
	Response *ResponseSelection `goblet:"response" json:"response,omitempty"`
	Security *SecuritySelection `goblet:"security" json:"security,omitempty"`
	//@deprecated
	Opened     bool                    `goblet:"opened" json:"opened,omitempty"`
	Parameters ParameterSelectionArray `goblet:"parameters" json:"parameters,omitempty"`
	//关于body的具体设置
	RequestBody *RequestBodySelection `goblet:"requestBody" json:"requestBody,omitempty"`
	InputMode   string                `goblet:"input_mode" json:"input_mode"`
}

type RequestBodySelection struct {
	Default string                         `goblet:"default" json:"default,omitempty"`
	Inputs  map[string]*ParameterSelection `goblet:"inputs" json:"inputs,omitempty"`
	Order   []string                       `goblet:"order" json:"order,omitempty"` //参数的渲染顺序，可调
}

type ResponseSelection struct {
	Default string `goblet:"default" json:"default"`
}

type SecuritySelection struct {
	Variables map[string]string `goblet:"variables" json:"variables"`
	Default   int               `goblet:"default" json:"default"`
}

type ParameterSelectionArray []*ParameterSelection

type ParameterSelection struct {
	Fixed      bool        `goblet:"fixed" json:"fixed"`
	Value      interface{} `goblet:"value" json:"value"`
	Calculated bool        `goblet:"calculated" json:"calculated"`
}

func (p *ParameterSelectionArray) ToMap(defs openapi3.Parameters) map[string]*ParameterSelection {
	var m = make(map[string]*ParameterSelection)
	for k, v := range *p {
		var def = defs[k]
		m[def.Value.Name] = v
	}
	return m
}
